/*
 * $Id: diffserv.h,v 1.28.6.2 Broadcom SDK $
 * 
 * $Copyright: Copyright 2011 Broadcom Corporation.
 * This program is the proprietary software of Broadcom Corporation
 * and/or its licensors, and may only be used, duplicated, modified
 * or distributed pursuant to the terms and conditions of a separate,
 * written license agreement executed between you and Broadcom
 * (an "Authorized License").  Except as set forth in an Authorized
 * License, Broadcom grants no license (express or implied), right
 * to use, or waiver of any kind with respect to the Software, and
 * Broadcom expressly reserves all rights in and to the Software
 * and all intellectual property rights therein.  IF YOU HAVE
 * NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS SOFTWARE
 * IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE
 * ALL USE OF THE SOFTWARE.  
 *  
 * Except as expressly set forth in the Authorized License,
 *  
 * 1.     This program, including its structure, sequence and organization,
 * constitutes the valuable trade secrets of Broadcom, and you shall use
 * all reasonable efforts to protect the confidentiality thereof,
 * and to use this information only in connection with your use of
 * Broadcom integrated circuit products.
 *  
 * 2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS
 * PROVIDED "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES,
 * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY,
 * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE.  BROADCOM SPECIFICALLY
 * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
 * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES,
 * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
 * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING
 * OUT OF USE OR PERFORMANCE OF THE SOFTWARE.
 * 
 * 3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL
 * BROADCOM OR ITS LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL,
 * INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY DAMAGES WHATSOEVER
 * ARISING OUT OF OR IN ANY WAY RELATING TO YOUR USE OF OR INABILITY
 * TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF
 * THE AMOUNT ACTUALLY PAID FOR THE SOFTWARE ITSELF OR USD 1.00,
 * WHICHEVER IS GREATER. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING
 * ANY FAILURE OF ESSENTIAL PURPOSE OF ANY LIMITED REMEDY.$
 * 
 * DO NOT EDIT THIS FILE!
 * This file is auto-generated.
 * Edits to this file will be lost when it is regenerated.
 */

#ifndef __BCM_DIFFSERV_H__
#define __BCM_DIFFSERV_H__

#include <bcm/filter.h>

/* Datapath direction, default is ingress. */
#define BCM_DS_EGRESS           0x001      
#define BCM_DS_INGRESS          0x002      

#define BCM_DS_UPDATE_INPROFILE     0x01       
#define BCM_DS_UPDATE_OUTPROFILE    0x02       

/* 
 * Traffic classifier flags.
 * 
 * When using TCP/UDP ports as part of classifier, the application must
 * use either a (L4_xxx_PORT_MIN, L4_xxx_PORT_MAX) pair, a (L4_xxx_PORT,
 * L4_xxx_MASK) pair or just use L4_xxx_PORT which implies a mask of
 * 0xffff.
 */
#define BCM_DS_CLFR_DST_MAC_ADDR            0x00000001 
#define BCM_DS_CLFR_SRC_MAC_ADDR            0x00000002 
#define BCM_DS_CLFR_VLAN_TAG                0x00000004 
#define BCM_DS_CLFR_ETHER_TYPE              0x00000008 
#define BCM_DS_CLFR_IP_VERSION              0x00000010 
#define BCM_DS_CLFR_IP_HLEN                 0x00000020 
#define BCM_DS_CLFR_IPV4_CODEPOINT          0x00000040 
#define BCM_DS_CLFR_IPV4_PROTOCOL           0x00000080 
#define BCM_DS_CLFR_IPV4_SRC_ADDR           0x00000100 
#define BCM_DS_CLFR_IPV4_SRC_PREFIX         0x00000200 
#define BCM_DS_CLFR_IPV4_DST_ADDR           0x00000400 
#define BCM_DS_CLFR_IPV4_DST_PREFIX         0x00000800 
#define BCM_DS_CLFR_IPV4_L4_SRC_PORT_MIN    0x00001000 
#define BCM_DS_CLFR_IPV4_L4_SRC_PORT_MAX    0x00002000 
#define BCM_DS_CLFR_IPV4_L4_DST_PORT_MIN    0x00004000 
#define BCM_DS_CLFR_IPV4_L4_DST_PORT_MAX    0x00008000 
#define BCM_DS_CLFR_IPV4_L4_SRC_PORT        0x00010000 
#define BCM_DS_CLFR_IPV4_L4_SRC_MASK        0x00020000 
#define BCM_DS_CLFR_IPV4_L4_DST_PORT        0x00040000 
#define BCM_DS_CLFR_IPV4_L4_DST_MASK        0x00080000 
#define BCM_DS_CLFR_PKT_FORMAT              0x00100000 

/* Diffserv classifier structure. */
typedef struct bcm_ds_clfr_s {
    uint32 cf_flags;                /* One or more of  BCM_DS_CLFR_xxx. */
    bcm_filter_format_t cf_pktfmt;  /* One or more of bcm_filter_format_t. */
    bcm_mac_t cf_dst_mac;           /* Destination MAC address. */
    bcm_mac_t cf_src_mac;           /* Source MAC address. */
    bcm_vlan_t cf_vid;              /* VLAN tag. */
    uint16 cf_ethertype;            /* Ether type of a packet. */
    uint8 cf_ip_version;            /* IP version number. */
    uint8 cf_ip_hlen;               /* IP header length. */
    uint8 cf_dscp;                  /* Diffserv codepoint. */
    uint8 cf_protocol;              /* IP Protocol number. */
    bcm_ip_t cf_src_ip_addr;        /* Source IPv4 address. */
    int cf_src_ip_prefix_len;       /* Source IP prefix length. */
    bcm_ip_t cf_dst_ip_addr;        /* Destination IP4 address. */
    int cf_dst_ip_prefix_len;       /* Destination IP prefix length. */
    uint16 cf_src_port_min;         /* Min. TCP/UDP source port number. */
    uint16 cf_src_port_max;         /* Max. TCP/UDP source port number. */
    uint16 cf_dst_port_min;         /* Min. TCP/UDP destination port number. */
    uint16 cf_dst_port_max;         /* Max. TCP/UDP destination port number. */
    uint16 cf_src_port;             /* TCP/UDP source port number. */
    uint16 cf_src_mask;             /* TCP/UDP source port mask. */
    uint16 cf_dst_port;             /* TCP/UDP destination port number. */
    uint16 cf_dst_mask;             /* TCP/UDP destination port mask. */
    int cf_precedence;              /* The precedence. */
} bcm_ds_clfr_t;

#define BCM_DS_ACTN_INSERT_PRIO             0x00000001 /* Affects COSQ and
                                                          packet. */
#define BCM_DS_ACTN_SET_PRIO                0x00000002 /* Affects COSQ only. */
#define BCM_DS_ACTN_INSERT_TOSP             0x00000004 /* IRULE.TOS_P */
#define BCM_DS_ACTN_COPY_TO_CPU             0x00000008 
#define BCM_DS_ACTN_DO_NOT_SWITCH           0x00000010 
#define BCM_DS_ACTN_SET_OUT_PORT_UCAST      0x00000020 /* IRULE.OUTPUTPORT */
#define BCM_DS_ACTN_COPY_TO_MIRROR          0x00000040 
#define BCM_DS_ACTN_INCR_FFPPKT_COUNTER     0x00000080 
#define BCM_DS_ACTN_INSERT_PRIO_FROM_TOSP   0x00000100 /* Affects COSQ and
                                                          packet. */
#define BCM_DS_ACTN_INSERT_TOSP_FROM_PRIO   0x00000200 /* Affects packet only. */
#define BCM_DS_ACTN_INSERT_DSCP             0x00000400 /* IRULE.DIFFSERV */
#define BCM_DS_ACTN_SET_OUT_PORT_NON_UCAST  0x00000800 /* IRULE.OUTPUTPORT */
#define BCM_DS_ACTN_DO_SWITCH               0x00002000 /* Overrides DO_NOT_SW. */
#define BCM_DS_ACTN_DROP_PRECEDENCE         0x00004000 
#define BCM_DS_ACTN_SET_OUT_PORT_ALL        0x00008000 /* IRULE.OUTPUTPORT */
#define BCM_DS_ACTN_SET_OUT_MODULE          0x00010000 /* IRULE.OUTPUTMOD */

/* Diffserv In-profile Action structure. */
typedef struct bcm_ds_inprofile_actn_s {
    uint32 ipa_flags;   /* One or more of BCM_DS_ACTN_xxx. */
    uint32 ipa_pri;     /* New priority for BCM_DS_ACTN_INSERT_PRIO and
                           BCM_DS_ACTN_SET_PRIO. */
    uint32 ipa_tos;     /* New IP TOS for BCM_DS_ACTN_INSERT_TOSP. */
    uint32 ipa_port;    /* Port for BCM_DS_ACTN_SET_OUT_PORT_xxx. */
    uint32 ipa_dscp;    /* New DSCP for BCM_DS_ACTN_INSERT_DSCP. */
    uint32 ipa_mod;     /* Module for BCM_DS_ACTN_SET_OUT_MODULE. */
} bcm_ds_inprofile_actn_t;

#define BCM_DS_OUT_ACTN_COPY_TO_CPU     0x00000001 
#define BCM_DS_OUT_ACTN_DO_NOT_SWITCH   0x00000002 
#define BCM_DS_OUT_ACTN_INSERT_DSCP     0x00000004 
#define BCM_DS_OUT_ACTN_DROP_PRECEDENCE 0x00000008 
#define BCM_DS_OUT_ACTN_DO_SWITCH       0x00000010 /* Overrides DO_NOT_SWITCH. */

/* Diffserv Out-of-profile Action structure. */
typedef struct bcm_ds_outprofile_actn_s {
    uint32 opa_flags;       /* One or more of BCM_DS_OUT_ACTN_xxx. */
    uint32 opa_dscp;        /* New DSCP for BCM_DS_OUT_ACTN_INSERT_DSCP. */
    uint32 opa_kbits_sec;   /* Average metered rate. */
    uint32 opa_kbits_burst; /* Meter's max allowable burst. */
} bcm_ds_outprofile_actn_t;

/* No-match actions (matches nothing but ingress port/modid). */
#define BCM_DS_NM_ACTN_INSERT_PRIO          0x00000001 /* Affects COSQ and
                                                          packet. */
#define BCM_DS_NM_ACTN_SET_PRIO             0x00000002 /* Affects COSQ only. */
#define BCM_DS_NM_ACTN_INSERT_TOSP          0x00000004 /* IMASK.TOS_P */
#define BCM_DS_NM_ACTN_COPY_TO_CPU          0x00000008 
#define BCM_DS_NM_ACTN_DO_NOT_SWITCH        0x00000010 
#define BCM_DS_NM_ACTN_SET_OUT_PORT_UCAST   0x00000020 /* IMASK.OUTPUTPORT */
#define BCM_DS_NM_ACTN_COPY_TO_MIRROR       0x00000040 
#define BCM_DS_NM_ACTN_INSERT_PRIO_FROM_TOSP 0x00000100 /* Affects COSQ and
                                                          packet. */
#define BCM_DS_NM_ACTN_INSERT_TOSP_FROM_PRIO 0x00000200 /* Affects packet only. */
#define BCM_DS_NM_ACTN_INSERT_DSCP          0x00000400 /* IMASK.DIFFSERV */
#define BCM_DS_NM_ACTN_SET_OUT_PORT_NON_UCAST 0x00000800 /* IMASK.OUTPUTPORT */
#define BCM_DS_NM_ACTN_DROP_PRECEDENCE      0x00001000 
#define BCM_DS_NM_ACTN_SET_OUT_PORT_ALL     0x00002000 /* IMASK.OUTPUTPORT */
#define BCM_DS_NM_ACTN_SET_OUT_MODULE       0x00004000 /* IMASK.OUTPUTMOD */

/* Diffserv No-match Action structure. */
typedef struct bcm_ds_nomatch_actn_s {
    uint32 nma_flags;   /* One or more of BCM_DS_NM_ACTN_xxx. */
    uint32 nma_pri;     /* New priority for BCM_DS_NM_ACTN_INSERT_PRIO and
                           BCM_DS_NM_ACTN_SET_PRIO. */
    uint32 nma_tos;     /* New IP TOS for BCM_DS_NM_ACTN_INSERT_TOSP. */
    uint32 nma_port;    /* Port for BCM_DS_NM_ACTN_SET_OUT_PORT_xxx. */
    uint32 nma_dscp;    /* New DSCP for BCM_DS_NM_ACTN_INSERT_DSCP. */
    uint32 nma_mod;     /* Module for BCM_DS_NM_ACTN_SET_OUT_MODULE. */
} bcm_ds_nomatch_actn_t;

/* Meter burst sizes are in kilobits (1000 bits). */
#define BCM_DS_METER_BURST_MIN  1          
#define BCM_DS_METER_BURST_MAX  20000      

/* Diffserv Scheduler structure. */
typedef struct bcm_ds_scheduler_s {
    int numq;                   /* Number of COS queues. */
    int weight[BCM_COS_COUNT];  /* Weight of a queue. */
} bcm_ds_scheduler_t;

/* Diffserv Counters structure. */
typedef struct bcm_ds_counters_s {
    uint64 inp_pkt_cntr;    /* In-profile packet counter. */
    uint64 outp_pkt_cntr;   /* Out-of-profile packet counter. */
} bcm_ds_counters_t;

/* bcm_ds_classifier_traverse_cb */
typedef int (*bcm_ds_classifier_traverse_cb)(
    int unit, 
    int dpid, 
    int cfid, 
    bcm_ds_clfr_t *clfr, 
    bcm_ds_inprofile_actn_t *inp_actn, 
    bcm_ds_outprofile_actn_t *outp_actn, 
    bcm_ds_nomatch_actn_t *nm_actn, 
    void *user_data);

#ifndef BCM_HIDE_DISPATCHABLE

/* Create a classifier within a datapath. */
extern int bcm_ds_classifier_create(
    int unit, 
    int dpid, 
    bcm_ds_clfr_t *clfr, 
    bcm_ds_inprofile_actn_t *inp_actn, 
    bcm_ds_outprofile_actn_t *outp_actn, 
    bcm_ds_nomatch_actn_t *nm_actn, 
    int *cfid);

/* Create a classifier within a datapath. */
extern int bcm_ds_classifier_create_id(
    int unit, 
    int dpid, 
    bcm_ds_clfr_t *clfr, 
    bcm_ds_inprofile_actn_t *inp_actn, 
    bcm_ds_outprofile_actn_t *outp_actn, 
    bcm_ds_nomatch_actn_t *nm_actn, 
    int cfid);

/* Update an existing classifier. */
extern int bcm_ds_classifier_update(
    int unit, 
    int dpid, 
    int cfid, 
    uint32 flags, 
    bcm_ds_inprofile_actn_t *inp_actn, 
    bcm_ds_outprofile_actn_t *outp_actn);

/* Delete a classifier from a datapath. */
extern int bcm_ds_classifier_delete(
    int unit, 
    int dpid, 
    int cfid);

/* Get a classifiers from a datapath. */
extern int bcm_ds_classifier_get(
    int unit, 
    int dpid, 
    int cfid, 
    bcm_ds_clfr_t *clfr, 
    bcm_ds_inprofile_actn_t *inp_actn, 
    bcm_ds_outprofile_actn_t *outp_actn, 
    bcm_ds_nomatch_actn_t *nm_actn);

/* Initialize the diffserv function. */
extern int bcm_ds_init(
    int unit);

/* Create a diffserv datapath. */
extern int bcm_ds_datapath_create(
    int unit, 
    uint32 flags, 
    bcm_pbmp_t ports, 
    int *dpid);

/* Create a diffserv datapath. */
extern int bcm_ds_datapath_create_id(
    int unit, 
    uint32 flags, 
    bcm_pbmp_t ports, 
    int dpid);

/* Delete a diffserv datapath and all associated classifiers. */
extern int bcm_ds_datapath_delete(
    int unit, 
    int dpid);

/* Install the datapath and all associated classifiers onto the hardware. */
extern int bcm_ds_datapath_install(
    int unit, 
    int dpid);

/* Add a scheduler to a diffserv datapath. */
extern int bcm_ds_scheduler_add(
    int unit, 
    int dpid, 
    bcm_ds_scheduler_t *scheduler);

/* Get packet counters for a classifier. */
extern int bcm_ds_counter_get(
    int unit, 
    int dpid, 
    int cfid, 
    bcm_ds_counters_t *counter);

/* Binding/un-binding a cookie with Datapath Id and classifier ID. */
extern int bcm_ds_dpid_cfid_bind(
    int unit, 
    void *mibid, 
    int dpid, 
    int cfid);

/* Binding/un-binding a cookie with Datapath Id and classifier ID. */
extern int bcm_ds_dpid_cfid_unbind(
    int unit, 
    void *mibid, 
    int dpid, 
    int cfid);

/* Get classifier ID based on datapath ID and cookie. */
extern int bcm_ds_dpid_cfid_get(
    int unit, 
    void *mibid, 
    int dpid, 
    int *cfid);

#endif /* BCM_HIDE_DISPATCHABLE */

/* Initialize a Diffserv classifier structure. */
extern void bcm_ds_clfr_t_init(
    bcm_ds_clfr_t *ds_clfr);

/* Initialize a Diffserv Inprofile Action structure. */
extern void bcm_ds_inprofile_actn_t_init(
    bcm_ds_inprofile_actn_t *ds_inprof_actn);

/* Initialize a Diffserv Out Of Profile Action structure. */
extern void bcm_ds_outprofile_actn_t_init(
    bcm_ds_outprofile_actn_t *ds_outprof_actn);

/* Initialize a Diffserv No Match Action structure. */
extern void bcm_ds_nomatch_actn_t_init(
    bcm_ds_nomatch_actn_t *ds_nomatch_actn);

/* Initialize a Diffserv Scheduler structure. */
extern void bcm_ds_scheduler_t_init(
    bcm_ds_scheduler_t *ds_sched);

/* Initialize a Diffserv Counters structure. */
extern void bcm_ds_counters_t_init(
    bcm_ds_counters_t *ds_count);

/* Backward compatibility. */
#define bcm_ds_classifier_id_create bcm_ds_classifier_create_id 

#ifndef BCM_HIDE_DISPATCHABLE

/* Traverse datapath classifiers. */
extern int bcm_ds_classifier_traverse(
    int unit, 
    int dpid, 
    bcm_ds_classifier_traverse_cb cb, 
    void *user_data);

#endif /* BCM_HIDE_DISPATCHABLE */

#endif /* __BCM_DIFFSERV_H__ */
